package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.ProductUnit;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.ProductUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("productUnit")
public class ProductUnitController {

    @Autowired
    private ProductUnitService productUnitService;

    @GetMapping("{id}")
    public Result findById(@PathVariable long id){

        return productUnitService.findById(id);

    }

    @GetMapping("{page}/{size}")
    public Result findAll(@PathVariable int page,@PathVariable int size){

        return productUnitService.findAll(page, size);

    }
    @GetMapping
    public Result findAllUnit(){
        return productUnitService.findAllUnit();
    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable long id){

        return productUnitService.deleteById(id);

    }

    @PostMapping
    public Result save(@RequestBody ProductUnit productUnit){
        System.out.println(productUnit.getName());
        return productUnitService.save(productUnit);

    }

    @PutMapping("{id}")
    public Result update(@RequestBody ProductUnit productUnit,@PathVariable Long id){

        return productUnitService.update(productUnit,id);

    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size){

        return productUnitService.Search(searchMap, page, size);

    }


}
